package com.tanhua.sso.controller;

import com.tanhua.sso.service.UserInfoService;
import com.tanhua.sso.vo.ErrorResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @Author YuShiLong
 * @Date 2021/4/12 18:58
 * @Version 1.0
 */
@RestController
@RequestMapping("user")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 完善个人信息-基本信息
     *
     * @param param
     * @return
     */
    @PostMapping("loginReginfo")
    public ResponseEntity<Object> loginReginfo(@RequestBody Map<String, String> param, @RequestHeader("Authorization") String token) {

        try {
            //调用业务层方法保持用户信息,将参数传递
            boolean bool = userInfoService.saveUserInfo(param,token);
            //判断执行的结果
            if (bool) {
                //根据执行的结果响应数据,执行成功响应ok
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage("用户信息保存失败!").build();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }

    /**
     * 完善个人信息-用户头像
     * @param file
     * @param token
     * @return
     */
//    @PostMapping("loginReginfo/head")
//    public ResponseEntity<Object> saveUserLogo(MultipartFile headPhoto, @RequestHeader("Authorization") String token) {
//
//        try {
//            //调用业务层方法保持用户头像,将参数传递
//            Boolean bool = userInfoService.saveUserLogo(headPhoto,token);
//            //判断执行的结果
//            if (bool) {
//                //根据执行的结果响应数据,执行成功响应ok
//                return ResponseEntity.ok(null);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage("用户头像保存失败!").build();
//        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
//    }
}
